#ifndef __SENSE_BARRIER_BARRIER_H__
#define __SENSE_BARRIER_BARRIER_H__

#include "IBarrier.h"
#include "cpp_framework.h"

class SBThreadLocal : public ThreadLocal<int>
{
public:
	int initialValue() { return 0; }
};

class SenseBarrier : public IBarrier {
private:
	CMDR::AtomicInteger _count;
	unsigned int _size;
	unsigned int volatile _sense;
	SBThreadLocal threadLocal;
public:
	
	/* C'tor */
	SenseBarrier(int n) : _size(n)
	{
		_count.set(n);
		_sense = 1;
	}
	
	/* D'tor */
	virtual ~SenseBarrier()
	{
	}
	
	/*
	 * Impl of the pure virtual function.  
	 */	
	void await();
	
	inline virtual char* getBarrierName()
	{
#ifdef WITHWAIT
		return "SenseBarrierWithWait";
#else 
		return "SenseBarrier";
#endif // WITHWAIT
	}
};


#endif /*__SENSE_BARRIER_BARRIER_H__*/
